<?php
/**
 * Created by JetBrains PhpStorm.
 * User: scala
 * Date: 12-10-25
 * Time: 上午10:03
 * To change this template use File | Settings | File Templates.
 */
class MessageAction extends CommonAction
{

    function index(){
        $message=M("Message");
        import("ORG.Util.Page");// 导入分页类
        $count=$message->count();
        $Page= new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page->setConfigArray(array('header'=>'条留言','prev'=>'<input type="button" value="<<<">','next'=>'<input type="button" value=">>>">','first'=>'首页','last'=>'尾页','theme'=>' %totalRow% %header% %nowPage%/%totalPage% 页   %first% %prePage% %upPage%   <span style="color: red;background-color: #7fffd4;">%linkPage%</span>   %downPage% %nextPage% %end%'));
        $show=$Page->show();//分页显示输出
        $list=$message->order("createtime desc ")->limit($Page->firstRow.",".$Page->listRows)->select();
        $this->assign("list",$list);
        $this->assign('page',$show);// 赋值分页输出
        $this->display();
    }




    function  delete(){
        $message=M("Message");
        if(!empty($_GET["id"])){
            $reply=M("MessageReply");
            $message->startTrans();
            $reply->where("messageid=".$_GET['id'])->delete();
            $message->delete($_GET["id"]);
            $message->commit();
        }
        $this->redirect("Message/index");
    }


    function  view(){
        $message=M("Message");
        if(!empty($_GET["id"])){
            $list= $message->find($_GET["id"]);
            $this->assign("list",$list);
            $reply=M("MessageReply");
            $replyList=$reply->where("messageid=".$_GET['id'])->select();
            $this->assign("replyList",$replyList);
        }
        $this->display();
    }


    function reply(){
        $news=D("MessageReply");
        if($result=$news->create()){
            $news->add();
            $this->redirect("Message/view",array("id"=>$result["messageid"]));
        }else{
            $this->error("回复出错!".$news->getError());
        }

    }

}
